<template>
  <el-dialog
    title="修改"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="指标" prop="zbCode">
        <el-input v-model="dataForm.zbCode" placeholder="指标名称" disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="最小阀值" prop="minValue">
        <el-input v-model.number="dataForm.minValue"></el-input>
      </el-form-item>
      <el-form-item label="最大阀值" prop="maxValue">
        <el-input v-model.number="dataForm.maxValue"></el-input>
      </el-form-item>
      <el-form-item label="监控等级" prop="zbLevel">
        <el-select v-model="dataForm.zbLevel">
          <el-option key="2001" label="每日推送" value="2001"></el-option>
          <el-option key="2002" label="实时可查" value="2002"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input type="textarea" v-model="dataForm.remark" placeholder="备注"></el-input>
      </el-form-item>
    </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="visible = false">取消</el-button>
          <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
        </span>
  </el-dialog>
</template>

<script>
  import API from '@/api'
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          zbCode: '',
          minValue: '',
          maxValue: '',
          zbLevel: '',
          remark: '',
          creator: this.$store.state.user.name
        }
      }
    },
    methods: {
      init (id) {
        this.getData(id)
        this.visible = true
      },
      getData (zbCode) {
        var params = {
          'zbCode': zbCode,
          'creator': this.$store.state.user.name
        }
        API.zbconfig.select(params).then(({data}) => {
          console.dir(data)
          this.dataForm.zbCode = data.zbCode
          this.dataForm.minValue = data.minValue
          this.dataForm.maxValue = data.maxValue
          this.dataForm.zbLevel = data.zbLevel
          this.dataForm.remark = data.remark
        })
      },
      dataFormSubmit () {
        var tick = API.zbconfig.update(this.dataForm)
        tick.then(({data}) => {
          if (data && data.code === 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.visible = false
                this.$emit('refreshDataList')
              }
            })
          } else {
            this.$message.error(data.msg)
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>
